
//此处不考虑泛型参数,只是基于String进行存储
class MyBlockingQueueClass {
    private String[] data=null;
    private volatile int head=0;
    private volatile int tail=0;
    private volatile int size=0;
    public MyBlockingQueueClass(int capacity) {
        data=new String[capacity];
    }

    private final Object locker=new Object();

    public void put(String s) throws InterruptedException {
        synchronized (locker) {
            while (size == data.length) {
                //队列满了,要极性阻塞
//                return;
                locker.wait();
            }
            data[tail] = s;
            tail++;
            if (tail >= data.length) tail = 0;
            size++;
            locker.notify();
        }
    }
    public String take() throws InterruptedException {
        String ret="";
        synchronized (locker) {
            while (size == 0) {
                //队列为空时进入阻塞状态
//                return null;
                locker.wait();//在put之后唤醒
            }
            ret = data[head];
            head++;
            if (head >= data.length) head = 0;
            size--;
            locker.notify();
        }
            return ret;
    }
}
public class MyBlockingQueue {
}
